/*     */ package com.zimbra.cs.mailbox.calendar;
/*     */ 
/*     */ import com.zimbra.common.calendar.ParsedDateTime;
/*     */ import com.zimbra.common.calendar.ParsedDuration;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class InviteChanges
/*     */ {
/*     */   public static final int LOCATION = 1;
/*     */   public static final int TIME = 2;
/*     */   public static final int RECURRENCE = 4;
/*     */   public static final int SUBJECT = 8;
/*     */   public static final String LABEL_LOCATION = "location";
/*     */   public static final String LABEL_TIME = "time";
/*     */   public static final String LABEL_RECURRENCE = "recurrence";
/*     */   public static final String LABEL_SUBJECT = "subject";
/*     */   
/*     */   private static void map(int mask, String label)
/*     */   {
/*  48 */     sMaskList.add(Integer.valueOf(mask));
/*  49 */     sMaskToLabel.put(Integer.valueOf(mask), label);
/*  50 */     sLabelToMask.put(label, Integer.valueOf(mask));
/*  51 */     String labelLower = label.toLowerCase();
/*  52 */     if (!labelLower.equals(label))
/*  53 */       sLabelToMask.put(labelLower, Integer.valueOf(mask));
/*     */   }
/*     */   
/*  56 */   private static List<Integer> sMaskList = new ArrayList();
/*  57 */   private static Map<Integer, String> sMaskToLabel = new HashMap();
/*  58 */   private static Map<String, Integer> sLabelToMask = new HashMap();
/*  59 */   static { map(1, "location");
/*  60 */     map(2, "time");
/*  61 */     map(4, "recurrence");
/*  62 */     map(8, "subject");
/*     */   }
/*     */   
/*     */ 
/*     */   public InviteChanges(Invite inv1, Invite inv2)
/*     */   {
/*  68 */     this.mChanges = 0;
/*  69 */     diffInvites(inv1, inv2);
/*     */   }
/*     */   
/*     */   public InviteChanges(String changesCSV) {
/*  73 */     this.mChanges = parse(changesCSV);
/*     */   }
/*     */   
/*  76 */   public boolean noChange() { return this.mChanges == 0; }
/*  77 */   private boolean changed(int bitmask) { return (this.mChanges & bitmask) != 0; }
/*  78 */   public boolean changedLocation() { return changed(1); }
/*  79 */   public boolean changedTime() { return changed(2); }
/*  80 */   public boolean changedRecurrence() { return changed(4); }
/*  81 */   public boolean changedSubject() { return changed(8); }
/*     */   
/*     */ 
/*     */ 
/*     */   private int mChanges;
/*     */   
/*     */ 
/*     */   public boolean isReplyInvalidatingChange()
/*     */   {
/*  90 */     return changed(7);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean isExceptionRemovingChange()
/*     */   {
/*  99 */     return (changedTime()) || (changedRecurrence());
/*     */   }
/*     */   
/*     */   private void diffInvites(Invite inv1, Invite inv2)
/*     */   {
/* 104 */     if (!StringUtil.equal(inv1.getName(), inv2.getName())) {
/* 105 */       this.mChanges |= 0x8;
/*     */     }
/*     */     
/* 108 */     if (!StringUtil.equal(inv1.getLocation(), inv2.getLocation())) {
/* 109 */       this.mChanges |= 0x1;
/*     */     }
/*     */     
/*     */ 
/* 113 */     ParsedDateTime dtStart1 = inv1.getStartTime();
/* 114 */     ParsedDateTime dtStart2 = inv2.getStartTime();
/* 115 */     boolean dtStartChanged; boolean dtStartChanged; if ((dtStart1 == null) || (dtStart2 == null)) {
/* 116 */       dtStartChanged = dtStart1 != dtStart2;
/*     */     } else
/* 118 */       dtStartChanged = !StringUtil.equal(dtStart1.getDateTimePartString(false), dtStart2.getDateTimePartString(false));
/* 119 */     if (dtStartChanged) {
/* 120 */       this.mChanges |= 0x2;
/*     */     }
/*     */     else
/*     */     {
/* 124 */       ParsedDateTime dtEnd1 = inv1.getEndTime();
/* 125 */       ParsedDateTime dtEnd2 = inv2.getEndTime();
/* 126 */       boolean dtEndChanged; boolean dtEndChanged; if ((dtEnd1 == null) || (dtEnd2 == null)) {
/* 127 */         dtEndChanged = dtEnd1 != dtEnd2;
/*     */       } else
/* 129 */         dtEndChanged = !StringUtil.equal(dtEnd1.getDateTimePartString(false), dtEnd2.getDateTimePartString(false));
/* 130 */       if (dtEndChanged) {
/* 131 */         this.mChanges |= 0x2;
/*     */       }
/*     */       else {
/* 134 */         ParsedDuration dur1 = inv1.getDuration();
/* 135 */         ParsedDuration dur2 = inv2.getDuration();
/* 136 */         boolean durationChanged; boolean durationChanged; if ((dur1 == null) || (dur2 == null)) {
/* 137 */           durationChanged = dur1 != dur2;
/*     */         } else
/* 139 */           durationChanged = !dur1.equals(dur2);
/* 140 */         if (durationChanged) {
/* 141 */           this.mChanges |= 0x2;
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 147 */     Recurrence.IRecurrence recur1 = inv1.getRecurrence();
/* 148 */     Recurrence.IRecurrence recur2 = inv2.getRecurrence();
/* 149 */     boolean recurChanged; boolean recurChanged; if ((recur1 == null) || (recur2 == null)) {
/* 150 */       recurChanged = recur1 != recur2;
/*     */     } else {
/* 152 */       recurChanged = !Recurrence.sameSeriesRules(recur1, recur2);
/*     */     }
/* 154 */     if (recurChanged)
/* 155 */       this.mChanges |= 0x4;
/*     */   }
/*     */   
/*     */   private static int parse(String changesCSV) {
/* 159 */     int changeMask = 0;
/* 160 */     String[] values = changesCSV.split(",");
/* 161 */     for (String value : values) {
/* 162 */       value = value.trim().toLowerCase();
/* 163 */       Integer i = (Integer)sLabelToMask.get(value);
/* 164 */       if (i != null)
/* 165 */         changeMask |= i.intValue();
/*     */     }
/* 167 */     return changeMask;
/*     */   }
/*     */   
/*     */   public String toString() {
/* 171 */     if (this.mChanges == 0)
/* 172 */       return "";
/* 173 */     StringBuilder sb = new StringBuilder();
/* 174 */     for (Integer i : sMaskList) {
/* 175 */       if (changed(i.intValue())) {
/* 176 */         if (sb.length() != 0)
/* 177 */           sb.append(',');
/* 178 */         sb.append((String)sMaskToLabel.get(i));
/*     */       }
/*     */     }
/* 181 */     return sb.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/calendar/InviteChanges.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */